package com.snowRemovingUser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.TSeason;
import com.snowRemovingUser.service.ITSeasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 季节Controller
 * 
 * @author lg
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/snowRemoving/season")
public class TSeasonController extends BaseController
{
    @Autowired
    private ITSeasonService tSeasonService;

    /**
     * 查询季节列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:season:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSeason tSeason)
    {
        startPage();
        List<TSeason> list = tSeasonService.selectTSeasonList(tSeason);
        return getDataTable(list);
    }

    /**
     * 导出季节列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:season:export')")
    @Log(title = "季节", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSeason tSeason)
    {
        List<TSeason> list = tSeasonService.selectTSeasonList(tSeason);
        ExcelUtil<TSeason> util = new ExcelUtil<TSeason>(TSeason.class);
        util.exportExcel(response, list, "季节数据");
    }

    /**
     * 获取季节详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:season:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSeasonService.selectTSeasonById(id));
    }

    /**
     * 新增季节
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:season:add')")
    @Log(title = "季节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSeason tSeason)
    {
        return toAjax(tSeasonService.insertTSeason(tSeason));
    }

    /**
     * 修改季节
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:season:edit')")
    @Log(title = "季节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSeason tSeason)
    {
        return toAjax(tSeasonService.updateTSeason(tSeason));
    }

    /**
     * 删除季节
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:season:remove')")
    @Log(title = "季节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSeasonService.deleteTSeasonByIds(ids));
    }
}
